//
//  RegisterOneCollectionViewCell.m
//  MJApp
//
//  Created by 王亮 on 15/8/25.
//  Copyright (c) 2015年 王亮. All rights reserved.
//

#import "RegisterOneCollectionViewCell.h"

@interface RegisterOneCollectionViewCell ()

@property(nonatomic,strong)UITextField *phoneTextField;

@end

@implementation RegisterOneCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    CGFloat wide = 0.6 * CGRectGetWidth(self.frame);
    CGFloat centerX = CGRectGetWidth(self.frame) / 2;
    UITextField *nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, wide, 30)];
    nameTextField.placeholder = @"输入手机号";
    nameTextField.layer.cornerRadius = CGRectGetHeight(nameTextField.frame) / 2;
    nameTextField.center = CGPointMake(centerX, nameTextField.center.y);
    nameTextField.backgroundColor = [UIColor whiteColor];
    nameTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
    nameTextField.leftViewMode = UITextFieldViewModeAlways;
    nameTextField.font = [UIFont systemFontOfSize:15];
    nameTextField.keyboardType = UIKeyboardTypeNumberPad;
    [self addSubview:nameTextField];
    self.phoneTextField = nameTextField;

    
    UIButton *loginIn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(nameTextField.frame) + 20, wide, 30)];
    [loginIn setTitle:@"获取验证码" forState:UIControlStateNormal];
    loginIn.backgroundColor = RGB(228, 41, 9);
    loginIn.titleLabel.font = [UIFont systemFontOfSize:15];
    loginIn.center = CGPointMake(centerX, loginIn.center.y);
    loginIn.layer.cornerRadius = CGRectGetHeight(loginIn.frame) / 2;
    [loginIn addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:loginIn];
}

- (void)login {
    
    if (![BCBaseObject isMobileNumber:self.phoneTextField.text]) {
        
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"手机号码不正确"];
        return;
    }
    if ([self.delegate respondsToSelector:@selector(cellProtocolWithObj:withDic:)]) {
        NSDictionary *dic = @{@"index":@"0",@"phone":self.phoneTextField.text};
        [self.delegate cellProtocolWithObj:self withDic:dic];
    }
}

@end
